package com.example.supernote.data.manager.impl

import com.example.supernote.model.manager.AbstractFileComposite
import com.example.supernote.model.manager.File
import com.example.supernote.model.manager.Folder
import com.example.supernote.data.manager.ManagerRepository
import com.example.supernote.model.manager.FileProperty
import com.example.supernote.model.manager.FileType
import java.util.Date

class FakeManagerRepository: ManagerRepository {
    private val testDepth = 3
    private var autoIncrementId = 1

    private fun createFolders(parent: AbstractFileComposite, depth: Int, num: Int)
    {
        if (depth > testDepth)
            return
        if (depth < testDepth) {
            for (i in 1..num) {
                val folder = Folder(
                    parent,
                    FileProperty(
                        name = "文件夹${depth}_${i}",
                        type = FileType.FOLDER,
                        lastModified = Date().time
                    )
                )
                createFolders(folder, depth + 1, num)
                parent.addChild(folder)
            }
        }
        else {
            for (i in 1..num) {
                val file = File(
                    parent,
                    FileProperty(
                        id = autoIncrementId,
                        name = "文件${depth}_${i}",
                        type = FileType.FILE,
                        lastModified = Date().time
                    )
                )
                autoIncrementId++
                parent.addChild(file)
            }
        }
        parent.children.shuffle()
    }
    override suspend fun getRoot(): AbstractFileComposite {
        val root = Folder(property = FileProperty(name = ".", type = FileType.ROOT, lastModified = Date().time))
        createFolders(root, 0, 3)
        return root
    }
}